package Analizadores;

import Calculadora.CalculadoraF;
import Calculadora.Simbolo;
import Calculadora.Numero;
import java.util.Iterator;
import java_cup.runtime.Symbol;


%%
%class AnalizadorLexico
%standalone
%public
%full
%unicode
%line
%column
%char
%cup
%{
    //Codigo Propio
    public Simbolo Buscar(String ID){
        Simbolo s;
        Iterator i = CalculadoraF.Simbolos.iterator();
        while(i.hasNext())
            if(ID.equals((s = (Simbolo)i.next()).getID()))
                return s;
        CalculadoraF.Simbolos.add(s = new Simbolo(ID));
        return s;
    }
%}
%eof{
    //al Funalizar
%eof}

sin = [Ss][IiEe][Nn]
cos = [Cc][Oo][Ss]
tan = [Tt][Aa][Nn]
asin = [Aa][Ss][IiEe][Nn]
acos = [Aa][Cc][Oo][Ss]
atan = [Aa][Tt][Aa][Nn]
finLinea = \r|\n|\r\n
espacioBlanco = {finLinea} | [ \t\f]
vEnt = [0-9][0-9]*
vExa = 0[xX][0-9a-fA-F]+
vOct = 0[oO][0-7]+
decimal = [0-9]*\.[0-9]+
id = [a-zA-Z_][a-zA-Z0-9_]*


%%
"*" {
    return new Symbol(sym.POR);
}
"+" {
    return new Symbol(sym.MAS);
}
"-" {
    return new Symbol(sym.SUB);
}
"/" {

    return new Symbol(sym.DIV);
}
"%" {

    return new Symbol(sym.MOD);
}
"^" {

    return new Symbol(sym.POW); 
}
{sin} {

    return new Symbol(sym.SIN, new Integer(sym.SIN));
}
{cos} {

    return new Symbol(sym.COS, new Integer(sym.COS));
}
{tan} {

    return new Symbol(sym.TAN, new Integer(sym.TAN));
}
{asin} {

    return new Symbol(sym.ASIN, new Integer(sym.ASIN));
}
{acos} {

    return new Symbol(sym.ACOS, new Integer(sym.ACOS));
}
{atan} {

    return new Symbol(sym.ATAN, new Integer(sym.ATAN));
}
"=" {
    return new Symbol(sym.ASIGNACION); 
}
"+=" {
    return new Symbol(sym.OP_AS);  
}
"-=" {
    return new Symbol(sym.OP_AS);  
}
"*=" {
    return new Symbol(sym.OP_AS);  
}
"/=" {
    return new Symbol(sym.OP_AS);  
}
"++" {
    return new Symbol(sym.INCDEC, new Integer(1));  
}
"--" {
    return new Symbol(sym.INCDEC, new Integer(2));  
}
"(" {
    return new Symbol(sym.PARENA);  
}
")" {
    return new Symbol(sym.PARENC);
}
{id} {

    return new Symbol(sym.ID, Buscar(yytext()));  
}
{vEnt} {

    return new Symbol(sym.CONST, new Numero(new Long(yytext())));   
}
{vExa} {

    return new Symbol(sym.CONST, new Numero(Integer.parseInt(yytext().replaceAll("0[Xx]", ""), 16)));
}
{vOct} {

    return new Symbol(sym.CONST, new Numero(Integer.parseInt(yytext().replaceAll("0[Oo]", ""), 8)));
}
{decimal} {

    return new Symbol(sym.CONST, new Numero(new Double(yytext())));
}
{finLinea} {/* ignorar */}
{espacioBlanco} {/* ignorar */}
. {
    //Interfaz.text.setText(Interfaz.text.getText() + "E{"+ yytext() +"}");
}